#include <iostream>
#include <string>
#include <stdio.h>

#include "HighPrecisionTimer.h"
#include "linkmap.h"

#ifdef _MSC_VER
#define snprintf _snprintf
#endif

int main() 
{
	HighPrecisionTimer timer;

    LinkMap<std::string, int> objLM;

    timer.start();
	for(long i = 1; i < 1000000; i++)
	{
		char szkey[20] = {0};
		sprintf(szkey, "link_%d", i);
		objLM.set(szkey, i);
	}
    timer.stop();

    char szbuf[128] = {0};;
    snprintf(szbuf, sizeof(szbuf), "elapsedSeconds=%I64u s", timer.elapsedSeconds());
	std::cout << "time: " << szbuf << "\n" << std::endl;

	timer.start();
    int val;
    if (objLM.get("link_999999", val)) {
        std::cout << "link_999999 = " << val << std::endl;
    }
	timer.stop();

    snprintf(szbuf, sizeof(szbuf), "elapsedMicroSeconds=%I64u ms", timer.elapsedMicroSeconds());
	std::cout << "time: " << szbuf << "\n" << std::endl;
	
	std::cout << "erase befor size: " << objLM.size() << std::endl;

    // 顺序遍历
	/*
    for (linkmap<std::string, int>::const_iterator it = objLM.begin();
         it != objLM.end(); ++it) {
        std::cout << it->first << " => " << it->second << std::endl;
    }*/

    objLM.erase("link_100");
    std::cout << "erase after size: " << objLM.size() << std::endl;

    return 0;
}